﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Text4();
        }
        static void Text4()
        {
            while (true)
            {
                Console.WriteLine("请输入一个数字");
                int a = int.Parse(Console.ReadLine());
                int[] arr2 = { 16, 5, 45, 1, 56, 78 };
                int num = Array.IndexOf(arr2, a);
                if (num == -1)
                {
                    Console.WriteLine("找不到");
                }
                else
                {
                    Console.WriteLine(a + "在数组中的位置索引为" + num);
                }

            }


        }
        static void Text3()
        {
            //定义一个方法，实现一维数组的排序功能，从大到小排序。(不要用Array类的方法)、
            int[] arr1 = { 16, 5, 45, 1, 56, 78 };
            int temp = 0;
            for (int i = 0; i < arr1.Length; i++)
            {
                for (int j = 0; j < arr1.Length - 1-i; j++)
                {
                    if (arr1[j] < arr1[j+1])
                    {
                        temp = arr1[j];
                        arr1[j] = arr1[j+1];
                        arr1[j + 1] =temp;
                    }
                }
            }
            for (int i = 0; i < arr1.Length; i++)
            {
                Console.WriteLine(arr1[i]+"\t");
            }

        }
        static void Text2()
        {
            // 在 Main 方法中创建一个 double 类型的数组，
            //并在该数组中存入 5 名学生的考试成绩(控制台输入)，计算总成绩和平均成绩。
            //要求使用foreach语句实现该功能，
            double[]arr = new double[5];
            double sum = 0;
            double avg = 0;
            for (int i = 0; i < arr.Length; i++)
            {
            Console.WriteLine("请输入5个学生的考试成绩");
            double a = double.Parse( Console.ReadLine());
                arr[i] = a;
            }
            foreach (double c in arr)
            {
                sum = sum + c;
                avg = sum / 5;
            }
            Console.WriteLine("总成绩是"+sum+"平均成绩为"+avg);
        }
        static void Text1()
        {
            //输入一行字符串，分别统计出其中英文字母、数字、空格的个数。
            Console.WriteLine("请输入一个字符串");
            string a = Console.ReadLine();
            int digitcount = 0;
            int Lettercount = 0;
            int WhiteSpacecount = 0;
            foreach (char item in a)
            {
                if (char.IsDigit(item))
                {
                    digitcount++;
                }
                if (char.IsLetter(item))
                {
                    Lettercount++;
                }
                if (Char.IsWhiteSpace(item))
                {
                    WhiteSpacecount++;
                }

            }
            Console.WriteLine("输入的字符串中有{0}个数字，{1}个字母,{2}个空格", digitcount, Lettercount, WhiteSpacecount);
        }
        static void Test7()
        {
            Console.WriteLine("空心正方形");
            Console.WriteLine("请输入正方形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    if (i == 0 || j == 0 || j == a - 1 || i == a - 1)
                    {
                        Console.Write("*" + " ");
                    }
                    else
                    {
                        Console.Write(" " + " ");
                    }
                }
                Console.WriteLine();
            }
        }

        static void Test8()
        {
            Console.WriteLine("菱形");
            Console.WriteLine("请输入菱形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    if (i == a)
                    {
                        Console.Write(" ");
                    }
                    else
                    {
                        Console.Write("*");
                    }
                }
                Console.WriteLine();
            }

            for (int i = 1; i < a + a; i++)
            {
                for (int j = 0; j < a + a; j++)
                {
                    if (i == a)
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }

        }
        static void Test9()
        {
            Console.WriteLine("实心正方形");
            Console.WriteLine("请输入正方形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    Console.Write("*" + " ");
                }
                Console.WriteLine();
            }
        }
    }
}
